package com.tech.koufu.ui.activity;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import org.apache.http.protocol.ResponseConnControl;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.Response.ErrorListener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.tech.koufu.MyApplication;
import com.tech.koufu.R; 
import com.tech.koufu.action.StockJson;
import com.tech.koufu.model.StockInfo;
import com.tech.koufu.model.UserStocks;
import com.tech.koufu.tools.CookieStringRequest;
import com.tech.koufu.tools.HttpUtils;
import com.tech.koufu.tools.KouFuTools;
import com.tech.koufu.tools.Statics;
import com.tech.koufu.ui.adapter.SimpleStockAdapter; 
import com.umeng.analytics.MobclickAgent;

import extras.com.handmark.pulltorefresh.library.PullToRefreshListView;
import android.app.Activity;
import android.app.Application;
import android.content.ClipData.Item;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;  
import android.text.format.DateFormat;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;

/**
 * 
 * @ClassName: SellStocksListActivity
 * @Description: 卖出列表/  
 * @author 123
 * @date 2015年3月29日 下午12:02:11
 */
public class SellStocksListActivity extends Activity implements OnClickListener{
	private static final String TAG = "SellStocksListActivity";
	
	private Context mContext;
	/**
	 * 0：卖出 
	 */
	private int type = 0; 
	private TextView pageTitle,tabStockSn,tv_title;
	private ArrayList<UserStocks> mUserStocks; 
	private PullToRefreshListView mPullToRefreshListView;
	private ListView actualListView;
	private SimpleStockAdapter mAdapter;
//	private RequestQueue mQueue; 
	private MyApplication myApp;
//	StringRequest stringRequest;
//	CookieStringRequest cookieStringRequest;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sell_stocks_list);  
		mContext = this;
		initView();
	}
	
	 @Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		MobclickAgent.onResume(mContext);
	}
	 
	 @Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		MobclickAgent.onPause(mContext);
	}
	private void initView(){
		pageTitle = (TextView)findViewById(R.id.kf_title);
		tabStockSn = (TextView)findViewById(R.id.tab_stock_sn);
		tv_title = ((TextView)findViewById(R.id.tv_title)); 
		findViewById(R.id.btn_refresh).setVisibility(View.GONE);
		findViewById(R.id.img_callback).setOnClickListener(this);;
		mPullToRefreshListView = (PullToRefreshListView)findViewById(R.id.lv_stocks);
		actualListView = mPullToRefreshListView.getRefreshableView(); 
        registerForContextMenu(actualListView);
        actualListView.setOnItemClickListener(itemClick);
        initData();
	}
	  
	private void initData(){ 
		tv_title.setText(R.string.btn_sell_stock); 
		mUserStocks = new ArrayList<UserStocks>();
		mUserStocks = (ArrayList<UserStocks>) getIntent().getSerializableExtra("userStock"); 
		mAdapter = new SimpleStockAdapter(getApplicationContext(),mUserStocks);
		mAdapter.type = type;
		actualListView.setAdapter(mAdapter);
//		mQueue = Volley.newRequestQueue(getApplicationContext());  
		myApp = (MyApplication) getApplication(); 
	}

	 
	
	
	private OnItemClickListener itemClick = new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) { 
			 
				Intent intent = new Intent(SellStocksListActivity.this,BuyStocksActivity.class);
				intent.putExtra("stockInfo", mUserStocks.get(position-1));
				intent.putExtra("type", 1);  
				startActivity(intent);
				SellStocksListActivity.this.finish();
		}
	};
	@Override
	public void onClick(View v) {
		 switch (v.getId()) {
		case R.id.img_callback:
			this.finish();
			break;

		default:
			break;
		}
		
	}

	@Override
	protected void onStop() { 
		super.onStop();
	 
	}
	
}
